<?php
$query = $_GET['q'];

//Database conenction info

try {
	$link = new PDO("mysql:host=localhost;dbname=helleb2_arb", "root", "");  //I changed this, your password is badadcde.
}
catch (PDOException $pe) {
	//echo "hi you!";
	die ($pe->getMessage());
}

if (strlen($query) >= 3) {
	$stmt=$link->prepare ("SELECT tree.id, name, donated_by, dedicated_to FROM tree LEFT OUTER JOIN donation ON tree.id = donation.tree_id 
	LEFT OUTER JOIN dedication ON donation.tree_id = dedication.tree_id WHERE (tree.name REGEXP (:query) OR donated_by REGEXP (:query) OR dedicated_to REGEXP (:query))");
	$stmt->bindParam (':query', $query);
	$stmt->execute();

	while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {

		echo "<a href=index.php?page=tree&value=" . $result['id'] . ">" . $result['name'] . "</a><br />";
		if ($result['donated_by']) {
			echo "Donated by: " . $result['donated_by'] . "<br />";
			if ($result['dedicated_to']) {
				echo "Dedicated to: " . $result['dedicated_to'] . "<br /><br />";
			}
			else {
				echo "<br />";
			}
		}
		else {
			echo "<br />";
		}
	}
}

//badabcde

?>

